package com.wuchao.util;

import com.wuchao.entity.User;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Author wuchao66
 * @Date 2022/7/8 16:12
 * @Version 1.0
 */
public class SysIntercept  extends HandlerInterceptorAdapter {//拦截器
    public boolean preHandle(
            HttpServletRequest request
            , HttpServletResponse response,
            Object handler) throws Exception{
        System.out.println("进入自定义拦截器==>SysInterceptor");
        //得到session
        HttpSession session = request.getSession();
        //session 是否存执，没有代表非法入参
        User user =(User)session.getAttribute("user");
        if(user!=null&&user.getName().equals("超哥")){
            return true;
        }else{
            return  false;
        }
        //true 放行 false  阻断gg 请求断了
    }

}
